Some computer architectures can support hardware and/or software transactional memory systems, such as Restricted Transactional Memory (RTM) systems and Software Transactional Memory (STM) systems. In transactional memory systems, computer instructions are permitted to execute concurrently, e.g. as single-threaded operations of a multi-threaded application. To do this, sequences of instructions in the computer program are defined as transactions, which can execute read and write instructions to shared memory independently of instructions running on other threads. The transactions can be defined by an interpreter, translator, program compiler, optimizer, or application programming interface (API), for example, depending on the type of transactional system.
The transactional memory system includes control mechanisms to prevent concurrently executing instructions from accessing shared memory at the same time or in the wrong order. For example, a validation mechanism verifies that a transaction has successfully completed, e.g., without other program threads making changes to memory accessed by the transaction before the transaction completed. If the validation is successful, the results of the transaction are made permanent (e.g. by a “commit” operation).
If the transaction cannot be committed, an exception may be raised or the transaction may be aborted. If an exception is raised or the transaction is aborted, execution of the transaction can be rolled back to an earlier point in the program code, e.g., to a “checkpoint.” If the transaction is aborted, it may be re-executed from the beginning until it completes successfully, or simply terminated.
Computer program code can contain many specialized instructions, each of which may be designed to handle a particular condition that may be satisfied during execution of the program. Code specialization is a program optimization technique that attempts to, at run-time, optimize a computer program or portion thereof for a commonly occurring condition. However, code specialization typically adds branch instructions that can affect performance.